//
//  UIButton+ActionEventBlock.m
//  BrillianceAD
//
//  Created by ZhouX on 16/6/14.
//  Copyright © 2016年 HYcompany. All rights reserved.
//

#import "UIButton+ActionEventBlock.h"

@implementation UIButton (ActionEventBlock)

static char overviewKey;

@dynamic event;

- (void)handleControlEvent:(UIControlEvents)event withBlock:(ZxActionBlock)block
{
    objc_setAssociatedObject(self, &overviewKey, block, OBJC_ASSOCIATION_COPY_NONATOMIC);
    [self addTarget:self action:@selector(callActionBlock:) forControlEvents:event];
}

- (void)callActionBlock:(id)sender
{
    ZxActionBlock block = (ZxActionBlock)objc_getAssociatedObject(self, &overviewKey);
    if (block)
    {
        block();
    }
}

@end
